<!--用户管理-->
<template>
  <div class="page-container">
    <page_breadcrumb :getKeyMethod="init_table_model" @change="change_table_model" pageOption />

    <ex_super_table_page v-bind="option" ref="SuperTablePage" @selection-change="e => selection = e">

      <template v-slot:bill-customer-info="{ row }">
        <!-- 客户:  -->
        <div style=" white-space: nowrap; text-overflow: ellipsis; overflow: hidden; ">{{ '[' + row.customerCode + '] ' +
          row.customerName }}</div>
        <!-- 账户:  -->
        <div style=" white-space: nowrap; text-overflow: ellipsis; overflow: hidden; ">{{ (row.accountType == 'CREDIT' ?
          ($enumShow(row.productType, 'PmsProductTypeEnum') + '-') : '') + $enumShow(row.currencyType, 'CurrencyTypeEnum')
          + '-' + $enumShow(row.accountType, 'CustomerAccountTypeEnum') }}</div>
      </template>

      <template v-slot:bill-product-info="{ row }">
        <div style=" white-space: nowrap; text-overflow: ellipsis; overflow: hidden; ">单号: {{ $enumShow(row.refOrderType,
          'OrderTypeEnum') }} - {{ row.refOrderNo }}</div>
        <div style=" white-space: nowrap; text-overflow: ellipsis; overflow: hidden; ">产品：{{ '[' + row.productCode + '] '
          + row.productName }}</div>
      </template>

      <template v-slot:bill-order-time="{ row }">
        <div style=" white-space: nowrap; text-overflow: ellipsis; overflow: hidden; ">创建: {{ $dateFormat(row.happenTime)
        }}</div>
        <div v-if="row.finishTime" style=" white-space: nowrap; text-overflow: ellipsis; overflow: hidden; ">完成: {{
          $dateFormat(row.finishTime) }}</div>
      </template>

      <template v-slot:bill-order-status="{ row }">
        <div>{{ $enumShow(row.status, 'FmsOrderStatus') }}</div>
        <div v-if="row.priceModel == 'OFFLINE' && row.versionPriceTag == 0">(等待报价)</div>
      </template>

    </ex_super_table_page>


    <fms-bill-detail-cmp ref="fmsBillDetailCmp"></fms-bill-detail-cmp>

    <fms-tenant-detail :fmsOrderId="fmsOrderId" ref="fmsTenantDetail"></fms-tenant-detail>

    <pms-offline-price-config ref="pmsOfflinePriceConfig" @afterSubmit="reload()"></pms-offline-price-config>

    <pms-online-price-config ref="pmsOnlinePriceConfig" @afterSubmit="reload()"></pms-online-price-config>

  </div>
</template>
<script>
import business_function from "@/common/business_function"


import SuperTablePageFunction from '@/mixin/super-table-page-function';
import page_table_model_manage from '@/mixin/page_table_model_manage';

import FmsTenantDetail from './dialog/fms-tenant-detail.vue'

import PmsOfflinePriceConfig from '@/component/pms/pms-offline-price-config.vue'

import PmsOnlinePriceConfig from '@/component/pms/pms-online-price-config.vue'

import bill_detail_info from '@/component/fms/bill_detail_info.vue'

import FmsBillDetailCmp from '@/component/fms/fms-bill-detail-cmp.vue'

export default {

  title: "label_fms_customer_order_manager",
  components: { FmsTenantDetail, PmsOfflinePriceConfig, PmsOnlinePriceConfig, bill_detail_info, FmsBillDetailCmp },

  mixins: [SuperTablePageFunction, page_table_model_manage],
  data() {


    return {
      selection: [],
      fmsOrderId: '-1',
      option: {
        search: {

          default: {
            refOrderType: this.orderType != 'ALL' ? this.orderType : ''
          },
          model: [
            {
              label: "label_fms_account_cmp_customer", key: "customerId", type: 'common_customer_choose', attrs: { multiple: false, },
            },
            {
              label: "label_fms_subject_order_type", key: "refOrderType", type: 'select', enum: 'OrderTypeEnum', attrs: {
                disabled: this.orderType != 'ALL',
                clearable: true
              }
            },
            {
              label: 'label_fms_subject_order_no', key: 'refOrderNo', type: 'input', attrs: { clearable: true }
            },
            {
              label: "label_warehouse", key: "warehouseId", type: 'base_warehouse_select', fold: false
            },
            {
              label: "label_create_time",
              key: "happenTimeStart",
              type: 'date-picker',
              attrs: { type: "datetime" },
            },
            {
              label: "-",
              key: "happenTimeEnd",
              type: 'date-picker',
              attrs: { type: "datetime" },
            },
            {
              label: "label_end_time",
              key: "finishTimeStart",
              type: 'date-picker',
              attrs: { type: "datetime" },
            },
            {
              label: "-",
              key: "finishTimeEnd",
              type: 'date-picker',
              attrs: { type: "datetime" },
            },
          ],
        },
        action: [
        ],
        actionExtra: [
          {
            if: () => this.orderType == 'ALL',
            label: 'label_outbound_export', click: this.exportExcelOutbound
          },
          {
            if: () => this.orderType == 'TENANT',
            label: 'label_export', click: this.exportExcel
          },
        ],
        table: {
          url: "/fms-api/customer/CustomerOrderRpc/select.json",
          attrs: {
            'cell-style': ({ row, column, rowIndex, columnIndex }) => {
              if (column.property == 'status') {
                return { color: row.status == 'NORMAL' ? this.$globalCss.successColor : this.$globalCss.infoColor }
              }
            }
          },
          model: this.init_table_model(),
        }
      },
    };
  },


  created() {

  },

  props: {
    orderType: {
      type: String,
      default: 'ALL'
    }
  },



  methods: {
    option_table_model() {
      return [
        { type: 'selection', clickToggle: true, keyGroup: 'label_table_operate' },

        {
          key: 'refOrderType', label: 'label_tms_waybill_order_info', align: 'left', 'min-width': 160,
          slot: 'bill-product-info'
        },
        {
          key: 'companyName', label: 'label_customer_account_info', align: 'left', 'min-width': 120,
          slot: 'bill-customer-info'
        },
        {
          key: 'supplyName', label: 'label_carrier', align: 'center', 'width': 120, if: () => this.orderType == 'ALL',
        },

        {
          key: 'totalAmount', label: 'label_fms_customer_order_total_amount', align: 'right', 'min-width': 90, attrs: {
            formatter: (r, c, v, i) => {
              return r.totalAmount + ' ' + r.currencyType
            }
          }
        },
        {
          key: 'priceModel', label: 'label_quotation_method', 'min-width': 100,
          attrs: {
            formatter: (r, c, v, i) => {
              return this.$enumShow(v, 'CustomerOrderPriceModelEnum')
            }
          }
        },
        {
          key: 'status', label: 'label_order_status', align: 'center', 'min-width': 100,
          slot: 'bill-order-status'
        },
        {
          key: 'finishTime', label: 'label_order_time', align: 'center', 'min-width': 120,
          slot: 'bill-order-time'
        },
        // 关联仓库
        {
          key: 'warehouseName', label: 'label_pms_ref_warehouse', align: 'center', 'min-width': 120,
          if: () => this.orderType == 'TENANT',
          attrs: {
            formatter: (r, c, v, i) => this.$formatNameCode(v, r.warehouseCode)
          }
        },
        {
          key: 'totalTenantSkuNum', label: 'label_total_sku_count', align: 'center', 'width': 120,
          if: () => this.orderType == 'TENANT',
        },
        {
          key: 'totalTenantVolume', label: 'label_total_volume', align: 'center', 'width': 120,
          if: () => this.orderType == 'TENANT',
          attrs: {
            formatter: (r, c, v, i) => this.$addUnit(v, "m³")
          }
        },

        {
          type: 'operate', width: 140,
          operate: [
            // '报价': '重新报价'
            {
              label: (row) => (row.versionPriceTag + '' == '0') ? this.$tt('label_quotation') : this.$tt('label_retry_quotation'),
              auth: 'fms_income_customer_order_quotation',
              if: (row) => {
                return row.priceModel == 'OFFLINE'
              },
              click: (row) => {
                this.fmsOrderId = row.id
                this.$refs['pmsOfflinePriceConfig'].showConfig(row.id)
              }
            },
            // 重算
            {
              label: 'label_retry_compute', auth: 'fms_income_customer_order_retry_compute',
              if: (row) => {
                return row.priceModel == 'ONLINE' && (row.productType == 'FIRST_TRANSPORT' || row.productType == 'LAST_TRANSPORT')
              },
              click: (row) => {
                this.fmsOrderId = row.id
                this.$refs['pmsOnlinePriceConfig'].showConfig(row)
              }
            },
            // 结算单
            {
              label: 'label_fms_customer_order_statement',
              if: (row) => {
                return row.refOrderType != 'TENANT'
              },
              click: (row) => {

                this.$refs['fmsBillDetailCmp'].showDetail(row)
              }
            },
            // 详情
            {
              label: 'label_detail',
              if: (row) => {
                return row.refOrderType == 'TENANT'
              },
              click: (row) => {
                this.fmsOrderId = row.id
                this.$refs['fmsTenantDetail'].showDetail()
              }
            }

          ],
        }
      ]
    },
    exportExcelOutbound() {
      let searchData = this.$refs.SuperTablePage.getSearchFormData()
      let list = this.selection
      if (_.isEmpty(list)) {
        searchData.refOrderType = "OUTBOUND"
      } else {
        if (list.some(it => it.refOrderType != "OUTBOUND")) {
          return this.$message.error("只能导出订单类型为出库订单")
        }
      }
      let url = "/fms-api/customer/CustomerOrderRpc/exportOutboundOrderExcel.json"
      if (this.orderType == 'TENANT') {
        url = "/fms-api/customer/CustomerOrderRpc/exportTenantExcel.json"
      }
      business_function.confirmOperateBaseSelectOrForm.call(this, {
        data: searchData,
        model: this.option.search.model,
        selection: list,
        callback: (selection, data) => {
          let params = {}
          if (!_.isEmpty(selection)) {
            params = {
              idList: selection.map(it => it.id)
            }
          } else {
            params = data
          }
          this.$functionCommon({
            url: url,
            data: params,
          })
        }
      })
    },
    exportExcel() {

      let url = "/fms-api/customer/CustomerOrderRpc/exportOutboundOrderExcel.json"
      if (this.orderType == 'TENANT') {
        url = "/fms-api/customer/CustomerOrderRpc/exportTenantExcel.json"
      }
      business_function.confirmOperateBaseSelectOrForm.call(this, {
        data: this.$refs.SuperTablePage.getSearchFormData(),
        model: this.option.search.model,
        selection: this.selection,
        callback: (selection, data) => {
          let params = {}
          if (!_.isEmpty(selection)) {
            params = {
              idList: selection.map(it => it.id)
            }
          } else {
            params = data
          }
          this.$functionCommon({
            url: url,
            data: params,
          })
        }
      })
    },

  }
};

</script>
<style></style>
